﻿using System;
using Microsoft.Owin.Hosting;
using Quartz;
using Yks.Notify.Client.Logging;

namespace Yks.Notify.Client.Services.Impl
{
    internal class NotifyClient : INotifyClient
    {
        private readonly IScheduler _scheduler;
        private readonly ILog _log;
        private IDisposable _web;

        public NotifyClient(IScheduler scheduler, ILog log)
        {
            _scheduler = scheduler;
            _log = log;
        }

        public void Start()
        {
            var appRootUrl = Configs.AppRootUrl;
            _web = WebApp.Start(appRootUrl);
            _log.Info($"WebApi Hosted on {appRootUrl}");
            _log.Info("Server Started");
        }

        public void Stop()
        {
            _scheduler.Shutdown();
            _web.Dispose();
            _log.Info("Server shutdown!");
        }
    }
}